package com.zhao.fishingguideserver.POJO;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


//前端试图统一后端返回类型
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Result<T> {
    private Integer code;
    // 新字段：与前端约定一致
    private String msg;
    // 兼容字段：为避免历史代码/工具依赖报错，继续保留并与msg同步
    private String message;
    private T data;

    public static <E> Result<E> success(E data){
        Result<E> r = new Result<>();
        r.setCode(0);
        r.setMsg("操作成功");
        r.setMessage("操作成功");
        r.setData(data);
        return r;
    }
    public static <E> Result<E> success(E data, String message){
        Result<E> r = new Result<>();
        r.setCode(0);
        r.setMsg(message);
        r.setMessage(message);
        r.setData(data);
        return r;
    }
    public static Result success(){
        Result r = new Result();
        r.setCode(0);
        r.setMsg("操作成功");
        r.setMessage("操作成功");
        r.setData(null);
        return r;
    }
    public static <E> Result<E> error(String message){
        Result<E> r = new Result<>();
        r.setCode(1);
        r.setMsg(message);
        r.setMessage(message);
        r.setData(null);
        return r;
    }
}
